<?php

/**
 * Created by PhpStorm.
 * User: lili
 * Date: 2018/11/9
 * Time: 17:00
 */
namespace app\index\model;


use think\Model;








class Article extends Model
{




    /*
     *
     * 获得新闻类型 的数量比例
     *
     *
     * */
    public function getProportionOfArticle(){
        $res = $this->field("count(*) as count,ll_cid ")->group('ll_cid')->select();
        return $res;
    }



    /*
     * 智能推荐比例
     *
     * */
    public function getPorportionOfshow($ll_uid){

        $rh = new Readhistory();
        $p1 = $rh->getHistory($ll_uid);
//        dump($p1->toArray());

        $p2 = $this->getProportionOfArticle();
//        dump(collection($p2)->toArray());

        $p3 = array('ppt'=>array(),'num'=>0);
        $num = 0;

        foreach ($p1->toArray() as $i => $v){

            if ($i == "ll_one" ){
                $p3['ppt']['ll_one'] = $v * $p2[0]["count"];
                $num+=$p3['ppt']['ll_one'];
            }
            if ($i == "ll_two" ){
                $p3['ppt']['ll_two'] = $v * $p2[1]["count"];
                $num+=$p3['ppt']['ll_two'];
            }
            if ($i == "ll_three" ){
                $p3['ppt']['ll_three'] = $v * $p2[2]["count"];
                $num+=$p3['ppt']['ll_three'];
            }
            if ($i == "ll_four" ){
                $p3['ppt']['ll_four'] = $v * $p2[3]["count"];
                $num+=$p3['ppt']['ll_four'];
            }
            if ($i == "ll_five" ){
                $p3['ppt']['ll_five'] = $v * $p2[4]["count"];
                $num+=$p3['ppt']['ll_five'];
            }
            if ($i == "ll_six" ){
                $p3['ppt']['ll_six'] = $v * $p2[5]["count"];
                $num+=$p3['ppt']['ll_six'];
            }
            if ($i == "ll_seven" ){
                $p3['ppt']['ll_seven'] = $v * $p2[6]["count"];
                $num+=$p3['ppt']['ll_seven'];
            }
            if ($i == "ll_eight" ){
                $p3['ppt']['ll_eight'] = $v * $p2[7]["count"];
                $num+=$p3['ppt']['ll_eight'];
            }

        }
        $p3['num'] = $num;
//        dump($p3);
        return $p3;

    }
    
    
    
    
    
    


}